package flc.ast.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.MyAlbumBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class AlbumAdapter extends StkProviderMultiAdapter<MyAlbumBean> {

    public AlbumAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(100));
        addItemProvider(new AlbumProvider());
    }

    private class AlbumProvider extends BaseItemProvider<MyAlbumBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_album;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, MyAlbumBean bean) {
            if (TextUtils.isEmpty(bean.getId())) {
                baseViewHolder.setImageResource(R.id.ivAlbumItemImg, R.drawable.aimage_xjxc);
                baseViewHolder.getView(R.id.ivAlbumItemAdd).setVisibility(View.VISIBLE);
                baseViewHolder.getView(R.id.llAlbumItem).setVisibility(View.GONE);
            } else {
                baseViewHolder.getView(R.id.ivAlbumItemAdd).setVisibility(View.GONE);
                baseViewHolder.getView(R.id.llAlbumItem).setVisibility(View.VISIBLE);
                if (bean.getListData() == null || bean.getListData().size() == 0) {
                    baseViewHolder.setImageResource(R.id.ivAlbumItemImg, R.drawable.aimage_zwxc);
                } else {
                    Glide.with(getContext()).load(bean.getListData().get(0))
                            .into((ImageView) baseViewHolder.getView(R.id.ivAlbumItemImg));
                }
                baseViewHolder.setText(R.id.tvAlbumItemName, bean.getName()+"  |");
                baseViewHolder.setText(R.id.tvAlbumItemNum, bean.getListData().size() + getContext().getString(R.string.unit_zhang));
            }
        }
    }
}
